<?php

/**
 * @author FROSTY (valik619)
 * @site nadmad.ru
 * @mail valik619@inbox.ru
 */

include('system/core.php');


$title = $lang['rigistration'];
include('system/head.php');

if (isset($_POST['submit'])) {
    
    
$nick = isset($_POST['nick']) ? trim($_POST['nick']) : '';
$pass = isset($_POST['password']) ? trim($_POST['pass']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
    $errors = 0;
    // Провiрка Логiнy
    if (empty($nick)){
        echo '<div class="menu">'.$lang['need_write_nick'].'</div>';
        $errors = 1;
    include('system/foot.php');
    exit; 
    }elseif (mb_strlen($nick) < 2 || mb_strlen($nick) > 15){
        echo '<div class="menu">'.$lang['error_leng'].'</div>';
    $errors = 1;
    include('system/foot.php');
    exit;   
    }
    
    if (empty($pass)) {
        echo '<div class="menu">'.$lang['need_write_pass'].'</div>';
    $errors = 1;
    include('system/foot.php');
    exit; 
    }elseif(mb_strlen($pass) < 6 || mb_strlen($pass) > 32){
        echo '<div class="menu">'.$lang['error_pass'].'</div>';
    $errors = 1;
    include('system/foot.php');
    exit; 
    }    
     if (preg_match('/[^\dA-Za-z]+/', $pass)){ 
        echo '<div class="menu">'.$lang['symbols_err'].'</div>';
    $errors = 1;
    include('system/foot.php');
    exit; 
    }
    if($pass != $password){
        echo '<div class="menu">'.$lang['pass_not_pass'].'</div>';
    $errors = 1;
    include('system/foot.php');
    exit; 
    }
    if($email != 'email'){
         echo '<div class="menu">SPAM DETECTED!!!</div>';
    $errors = 1;
    include('system/foot.php');
    exit; 
    }
   
        $parol = md5(md5($pass));
        $nick = functions::check(mb_substr($nick, 0, 20));
//Можливо нік занятий...
        $req = mysql_query("SELECT * FROM `users` WHERE `nick`='" . mysql_real_escape_string($nick) . "'");
        if (mysql_num_rows($req) != 0) {
            echo '<div class="menu">'.$lang['this_nick'].'</div>';
        $errors = 1;
        }
    
if($errors == 0){
        mysql_query("INSERT INTO `users` SET
            `nick` = '" . mysql_real_escape_string($nick) . "',
            `pass` = '" . mysql_real_escape_string($parol) . "',
            `name` = '" . mysql_real_escape_string($nick) . "',
            `about` = '',
            `city` = '',
            `mail` = '',
            `vk` = '',
            `sex` = '0',
            `rights` = '0',
            `reg_time` = '".time()."',
            `design` = '$set[design]',
            `mainmenu` = '$set[mainmenu]',
            `kmess` = '$set[kmess]',
            `online` = '".time()."'
        ");
        $usid = mysql_insert_id();
		
        echo '<div class="menu"><p><h3>'.$lang['congratilations'].'</h3><br/>Nick: <b>' . $nick . '</b><br/>Pass: <b>' . $pass . '</b></p>';

        echo '<div class="gmenu"><form action="login.php" method="post"><p>Нік: (max. 20)<br/>' .
         '<input type="text" name="nick" value="' . htmlentities($nick, ENT_QUOTES, 'UTF-8') . '" maxlength="20"/>' .
         '<br/>Пароль: (max 32)<br/>' .
         '<input type="password" name="pass" maxlength="32" value="'.$pass.'"/></p>' .
         '<p><input type="submit" value="'.$lang['enter'].'"/></p>' .
         '</form></div>';
        
        echo '</p></div>';
        require('system/foot.php');
        exit;
    }   
    
}else{


echo '<div class="title">'.$lang['rigistration'].'</div>';
echo '<div class="menu">';
echo '<form action="reg.php" method="post">';
echo 'Login: (2-15)<br />';
echo '<input type="name" name="nick" maxlength="30" value="" /><br />';
echo 'Password: (6-32)<br />';
echo '<input type="password" name="pass" maxlength="32" value="" /><br />';
echo 'Password again:<br />';
echo '<input type="password" name="password" maxlength="32" value="" /><br />';
echo '<input type="hidden" name="email" value="email" /><br />'; //гг это такая защита от спама
echo '<input type="submit" name="submit" value="Продовжити"/></form>';
echo 'Всі поля обовязкові до заповнення!';
echo '</div>';
include('system/foot.php');
}


/**
 * @author FROSTY (valik619)
 * @site nadmad.ru
 * @mail valik619@inbox.ru
 */

?>